﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DatVeB3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (
            Session["LoaiChuyenBay"] != null
            && Session["IDsanBayDi"] != null
            && Session["IDsanBayDen"] != null
            && Session["TensanBayDi"] != null
            && Session["TensanBayDen"] != null
            && Session["NgayDi"] != null
            && Session["NgayDen"] != null
            && Session["Adults"] != null
            && Session["MaCBDi"] != null
            && Session["HangDi"] != null)
        {
            if (!IsPostBack)
            {
            }
        }
        else
        {
            Response.Redirect("Home.aspx");
        }
    }
    //protected void Button1_Click(object sender, EventArgs e)
    //{
    //    Response.Write("<script language='JavaScript'> alert('Đăng Ký thành công. Email xác nhận sẽ được gửi vào hộp thư của bạn. Xin cảm ơn!'); </script>");
    //}
    protected void Button3_Click(object sender, EventArgs e)
    {
        List<KhachHang> listkh = new List<KhachHang>();
        KhachHang kh = new KhachHang();
        kh.LoaiDoiTuong = 1;
        kh.HoTenKhachHang = TextBox1.Text.Trim();
        kh.Email = TextBox6.Text;
        kh.GioiTinh = (RadioButtonList1.SelectedIndex==0)?true:false;
        kh.LoaiGiayTo = RadioButtonList2.SelectedItem.Text;
        kh.NgayHetHan = DateTime.Parse(TextBox9.Text);
        kh.NgaySinh = DateTime.Parse(TextBox10.Text);
        kh.NuocPhatHanh = DropDownList6.SelectedItem.Text;
        kh.QuocTich = DropDownList1.SelectedItem.Text;
        kh.SoDienThoaiBan = TextBox4.Text;
        kh.SoDienThoaiDiDong = TextBox5.Text;
        kh.SoThe = TextBox3.Text;

        int nAdult = int.Parse(Session["Adults"].ToString());
        int nChild212 = 0;
        if(Session["Children2-12"]!=null)
        {
            nChild212 = int.Parse(Session["Children2-12"].ToString());
        }
        int nChild2 = 0;
        if (Session["Childrenless2"] != null)
        {
            nChild2 = int.Parse(Session["Childrenless2"].ToString());
        }

        for (int i = 0; i < nAdult; i++)
        {
            KhachHang kh1 = new KhachHang();
            kh1.Email = kh.Email;
            kh1.GioiTinh = kh.GioiTinh;
            kh1.HoTenKhachHang = kh.HoTenKhachHang;
            kh1.LoaiDoiTuong = kh.LoaiDoiTuong;
            kh1.LoaiGiayTo = kh.LoaiGiayTo;
            kh1.NgayHetHan = kh.NgayHetHan;
            kh1.NgaySinh = kh.NgaySinh;
            kh1.NuocPhatHanh = kh.NuocPhatHanh;
            kh1.QuocTich = kh.QuocTich;
            kh1.SoDienThoaiBan = kh.SoDienThoaiBan;
            kh1.SoDienThoaiDiDong = kh.SoDienThoaiDiDong;
            kh1.SoThe = kh.SoThe;
            
            listkh.Add(kh1);
        }
        for (int i = 0; i < nChild212; i++)
        {
            KhachHang kh1 = new KhachHang();
            kh1.Email = kh.Email;
            kh1.GioiTinh = kh.GioiTinh;
            kh1.HoTenKhachHang = kh.HoTenKhachHang;
            kh1.LoaiDoiTuong = 2;
            kh1.LoaiGiayTo = kh.LoaiGiayTo;
            kh1.NgayHetHan = kh.NgayHetHan;
            kh1.NgaySinh = kh.NgaySinh;
            kh1.NuocPhatHanh = kh.NuocPhatHanh;
            kh1.QuocTich = kh.QuocTich;
            kh1.SoDienThoaiBan = kh.SoDienThoaiBan;
            kh1.SoDienThoaiDiDong = kh.SoDienThoaiDiDong;
            kh1.SoThe = kh.SoThe;

            listkh.Add(kh1);
        }
        for (int i = 0; i < nChild2; i++)
        {
            KhachHang kh1 = new KhachHang();
            kh1.Email = kh.Email;
            kh1.GioiTinh = kh.GioiTinh;
            kh1.HoTenKhachHang = kh.HoTenKhachHang;
            kh1.LoaiDoiTuong = 3;
            kh1.LoaiGiayTo = kh.LoaiGiayTo;
            kh1.NgayHetHan = kh.NgayHetHan;
            kh1.NgaySinh = kh.NgaySinh;
            kh1.NuocPhatHanh = kh.NuocPhatHanh;
            kh1.QuocTich = kh.QuocTich;
            kh1.SoDienThoaiBan = kh.SoDienThoaiBan;
            kh1.SoDienThoaiDiDong = kh.SoDienThoaiDiDong;
            kh1.SoThe = kh.SoThe;

            listkh.Add(kh1);
        }
        Session.Add("email", TextBox6.Text);
        Session.Add("ListKH", listkh);

        Response.Redirect("DatVeKetThuc.aspx#divDatVeB");
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Session.Remove("MaCBDi");
        Session.Remove("MaCBVe");
        Session.Remove("HangDi");
        Session.Remove("HangVe");
        Response.Redirect("DatVeB2.aspx#divDatVeB");
    }
}